<template>
  <div class="pageBox">
    <div v-if="isShowSkeleton" class="mt20">
      <van-skeleton title :row="5" />
    </div>
    <div v-else>
      <div class="swipe bg-ff">
        <van-swipe :autoplay="3000" lazy-render>
          <van-swipe-item v-for="item in recommendList" :key="item.id">
            <a :href="`/menu/detail/${item.id}`" target="_self">
              <img :src="handleImgSrc(item.photo_url)" class="banner_img" />
            </a>
          </van-swipe-item>
        </van-swipe>
      </div>

      <div class="userBox bg-ff mt15">
        <div v-if="user.userInfo?.id" class="flexBox flexBetween aiCenter">
          <div class="flexBox aiCenter">
            <img :src="handleImgSrc(user.userInfo?.avatar)" alt="" class="avatar mr15">
            <div>
              <span class="block fs26">欢迎您</span>
              <span class="bloock fs28 f600">{{ user.userInfo?.nickname }}</span>
            </div>
          </div>
          <div class="textCenter fs24 c-666" @click="router.push('/user/signIn')">
            <span class="block fs28 c-main-1">签到</span>
            <span class="block fs24 c-666">领饭币</span>
          </div>
        </div>
        <div v-else>
          <div class="flexBox aiCenter pt15 pb15">
            <img :src="avatar" alt="" class="avatar mr30">
            <div class="flexBox">
              <p class="fs28 c-666 f600">暂未登录，</p>
              <RouterLink to="/login" class="fs28 c-main f600">立即登录</RouterLink>
            </div>
          </div>
        </div>
      </div>

      <div class="recommend bg-ff mt15">
        <h1 class="fs32 pl25">推荐</h1>
        <div class="flexBox flexWrap flexAround mt30">
          <a :href="`/menu/detail/${item.id}`" v-for="item in recommendList" :key="item.id" class="menuItem textCenter">
            <img :src="handleImgSrc(item.photo_url)" alt="" class="food">
            <span class="fs28 block mt15">{{ item.name }}</span>
            <span class="fs26 block mt5 c-main-1">{{ item.fee }}</span>
          </a>
        </div>
      </div>

      <!-- <div class="footer textCenter mt30">
      <div class="flexBox aiCenter flexcenterX">
        <img src="@/assets/images/beian.png" alt="" class="baImg">
        <div class="fs24 c-666 ml15">
          粤公网安备 44030502000135号
        </div>
      </div>
      <a href="https://beian.miit.gov.cn" target="_blank" class="fs24 c-666 textCenter mt5">粤ICP备2025389861号</a>
    </div> -->
    </div>
  </div>
</template>

<script setup lang="ts">
import { recommendMenu } from '@/api/menu'
import { userStore } from '@/store'
import { handleImgSrc } from '@/utils'
import { onMounted, ref } from 'vue'
import { MenuItemType } from '@/types/menuTypes'
import avatar from '@/assets/images/avatar.jpg'
import router from '@/router'
const user = userStore()

const isShowSkeleton = ref(true)
const recommendList = ref<MenuItemType[]>([])

const getList = async () => {
  const { data } = await recommendMenu()
  if (data.code === 0) {
    isShowSkeleton.value = false
    recommendList.value = data.data.entries
  }
}

onMounted(() => {
  getList()
})
</script>

<style lang="scss" scoped>
.pageBox {
  background: #F7F7F7;
  padding-top: 15px;
  padding-bottom: 15px;
  overflow-y: auto;

  .swipe {
    padding: 0 10px;

    .van-swipe {
      border-radius: 10px;
    }

    .banner_img {
      width: 100%;
      height: 400px;
      object-fit: fill;
    }
  }

  .userBox {
    padding: 15px 25px;
    margin-left: 10px;
    margin-right: 10px;
    border-radius: 10px;

    .avatar {
      max-width: 120px;
      border-radius: 50%;
    }
  }

  .recommend {
    padding: 15px 10px;
    margin-left: 10px;
    margin-right: 10px;
    border-radius: 10px;

    .menuItem {
      width: 45%;
      margin-bottom: 20px;

      &:nth-child(2n) {
        margin-bottom: 0;
      }

      .food {
        width: 120px;
        height: 120px;
        border-radius: 50%;
      }
    }
  }

  .footer {
    .baImg {
      width: 30px;
      height: 30px;
    }
  }
}
</style>